package com.lingyu.jsjx.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.lingyu.jsjx.domain.CoursePlan;
import com.lingyu.jsjx.domain.dto.TeachingReflectionDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.lingyu.jsjx.domain.TeachingReflection;
import com.lingyu.jsjx.service.ITeachingReflectionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 教学反思
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/teachingReflection")
public class TeachingReflectionController extends BaseController
{
    @Autowired
    private ITeachingReflectionService teachingReflectionService;

    /**
     * 查询教学反思列表
     */
    @RequiresPermissions("jsjx:teachingReflection:list")
    @GetMapping("/list")
    public TableDataInfo list(TeachingReflectionDTO teachingReflectionDTO)
    {
        startPage();
        List<TeachingReflection> list = teachingReflectionService.selectTeachingReflectionList(teachingReflectionDTO);
        return getDataTable(list);
    }

    /**
     * 导出教学反思列表
     */
    @RequiresPermissions("jsjx:teachingReflection:export")
    @Log(title = "教学反思", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingReflectionDTO teachingReflectionDTO)
    {
        List<TeachingReflection> list = teachingReflectionService.selectTeachingReflectionList(teachingReflectionDTO);
        ExcelUtil<TeachingReflection> util = new ExcelUtil<TeachingReflection>(TeachingReflection.class);
        util.exportExcel(response, list, "教学反思数据");
    }

    /**
     * 获取教学反思详细信息
     */
    @RequiresPermissions("jsjx:teachingReflection:query")
    @GetMapping(value = "/{reflectionId}")
    public AjaxResult getInfo(@PathVariable("reflectionId") Long reflectionId)
    {
        return success(teachingReflectionService.selectTeachingReflectionByReflectionId(reflectionId));
    }

    /**
     * 新增教学反思
     */
    @RequiresPermissions("jsjx:teachingReflection:add")
    @Log(title = "教学反思", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingReflection teachingReflection)
    {
        return toAjax(teachingReflectionService.insertTeachingReflection(teachingReflection));
    }

    /**
     * 修改教学反思
     */
    @RequiresPermissions("jsjx:teachingReflection:edit")
    @Log(title = "教学反思", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingReflection teachingReflection)
    {
        return toAjax(teachingReflectionService.updateTeachingReflection(teachingReflection));
    }

    /**
     * 删除教学反思
     */
    @RequiresPermissions("jsjx:teachingReflection:remove")
    @Log(title = "教学反思", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reflectionIds}")
    public AjaxResult remove(@PathVariable Long[] reflectionIds)
    {
        return toAjax(teachingReflectionService.deleteTeachingReflectionByReflectionIds(reflectionIds));
    }

    @Log(title = "教学反思", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<TeachingReflection> util = new ExcelUtil<>(TeachingReflection.class);
        List<TeachingReflection> teachingReflectionList = util.importExcel(file.getInputStream());
        String message = teachingReflectionService.importTeachindReflection(teachingReflectionList, false);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<TeachingReflection> util = new ExcelUtil<>(TeachingReflection.class);
        util.importTemplateExcel(response, "课程计划数据");
    }
}
